package com.wenhai.spring.application.context.lifecycle;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.Lifecycle;
import org.springframework.context.support.GenericApplicationContext;

/**
 * 自定义{@link Lifecycle} Bean 示例
 *
 * @author wenhai
 * @date   2021/4/13
 * @see Lifecycle
 */
public class LifecycleDemo {
    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();
        context.registerBeanDefinition("myLifecycle", BeanDefinitionBuilder.rootBeanDefinition(MyLifecycle.class).getBeanDefinition());
        context.refresh();

        context.start();

        context.stop();

        context.close();
    }
}
